-- summon_die_skill
-- created by zhuangsl
-- 击杀敌人触发技能

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,
    -- 触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_SUMMON then
            return;
        end
        
        -- 不满足概率
        if DungeonM.getRandSeed("summon_attack_skill") % 1000 >= prop[3] then
            return;
        end
        
        local skillId = tonumber(prop[2]);
        local target;
        if not SkillM.needTarget(skillId) then
            target = who;
        elseif not arg:isDead() then
            target = arg;
        else
            for p = 1, DUNGEON_WIDTH * DUNGEON_HEIGHT do
                local grid = DungeonM.getGridByPos(p);

                -- 是未死亡的怪物
                if grid:isOpened() and
                    grid:isMonster() and
                    not grid.monster:isDead() then
                    target = grid.monster;
                    break;
                end
            end
            
            -- 已经没有目标了，不处理
            if not target then
                return;
            end
        end

        -- 触发技能
        local round = CombatM.getRound();

        SkillM.apply(who, target, skillId, round);
    end,

    record = function(target, prop, path)
        return false;
    end
};
